<template>
  <el-dialog title="驳回理由" :visible.sync="visible" width="600px">
    <div class="add-form">
      <el-form ref="form" :model="form" label-width="0">
        <el-form-item
          label=""
          :rules="[
            { required: true, message: '请输入驳回理由', trigger: 'blur' }
          ]"
          prop="reason"
        >
          <el-input
            type="textarea"
            rows="5"
            v-model="form.reason"
            placeholder="请输入驳回理由"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
	getWorkOrderAbnormalPage,
  workOrderReject // 异常工单驳回
} from "@/api/workorder";

export default {
  data() {
    return {
      visible: false,
      orderData: {},
      form: {
        reason: ""
      }
    };
  },
  methods: {
    show(data) {
      this.orderData = data;
      this.visible = true;
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          workOrderReject(this.getParams()).then(res => {
            if (res.data.code === 200) {
              this.$message({
                type: "success",
                message: `驳回成功！`
              });
              this.visible = false;
              this.$emit("submit");
            } else {
              this.$message({
                type: "error",
                message: res.data.msg
              });
            }
          });
        }
      });
    },
    getParams() {
      const params = {
        id: this.orderData.id,
        ...this.form
      };
      return params;
    }
  }
};
</script>

<style lang="scss" scoped>
.add-form {
}
</style>
